import { apiClient } from './axios';

// 用户管理相关接口
export const usersApi = {
  // 获取用户列表
  getUsers: (params?: {
    page?: number;
    per_page?: number;
    search?: string;
    role?: string;
    is_active?: boolean;
    area_id?: number;
  }) => {
    return apiClient.get('/users', { params });
  },

  // 获取单个用户详情
  getUser: (userId: number) => {
    return apiClient.get(`/users/${userId}`);
  },

  // 创建用户
  createUser: (userData: {
    username: string;
    password: string;
    name: string;
    email?: string;
    phone?: string;
    role: string;
    area_id?: number;
    position?: string;
    is_active?: boolean;
  }) => {
    return apiClient.post('/users', userData);
  },

  // 更新用户
  updateUser: (userId: number, userData: {
    name?: string;
    email?: string;
    phone?: string;
    role?: string;
    area_id?: number;
    position?: string;
    is_active?: boolean;
  }) => {
    return apiClient.put(`/users/${userId}`, userData);
  },

  // 删除用户
  deleteUser: (userId: number) => {
    return apiClient.delete(`/users/${userId}`);
  },

  // 重置用户密码
  resetPassword: (userId: number, newPassword: string) => {
    return apiClient.post(`/users/${userId}/reset-password`, {
      new_password: newPassword
    });
  },

  // 切换用户状态
  toggleUserStatus: (userId: number) => {
    return apiClient.put(`/users/${userId}/toggle-status`);
  },

  // 获取用户选项列表（用于下拉选择）
  getUserOptions: (params?: { role?: string; area_id?: number }) => {
    return apiClient.get('/users/options', { params });
  }
};